package com.fzshang.shopping.wx.controller;


import com.fzshang.shopping.commen.bean.ShoppingCar;
import com.fzshang.shopping.commen.controller.BaseController;
import com.fzshang.shopping.commen.entity.ApiResult;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 冯政尚
 * @since 2020-03-14
 */
@Controller
@RequestMapping("wx/shoppingCar")
public class WXShoppingCarController extends BaseController {

    /**
     * @param shoppingCar
     * @return 添加购物车
     */
    @RequestMapping(value = "saveShoppingCar")
    @ResponseBody
    public ApiResult saveShoppingCar(@RequestBody ShoppingCar shoppingCar){
        shoppingCar.setCreateTime(System.currentTimeMillis());
        if(shoppingCarService.save(shoppingCar)){
            return ApiResult.ok();
        }
        return ApiResult.fail();
    }

    /**
     * @param id
     * @return 取消购物车
     */
    @RequestMapping(value = "cancelShoppingCar")
    @ResponseBody
    public ApiResult cancelShoppingCar(Long id){
        if(shoppingCarService.removeById(id)){
            return ApiResult.ok();
        }
        return ApiResult.fail();
    }

}
